home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’95 / NetFractal™ / Fractal 8 source / ScreenTarget.cpp < prev    next >
Encoding:
Text File  |  1995-06-24  |  1.9 KB  |  96 lines  |  [TEXT/MPCC]

  1. //    ScreenTarget.cpp
  2.  
  3.  
  4. #include "ScreenTarget.h"
  5. #include <QDOffscreen.h>
  6.  
  7.  
  8. ScreenTarget::ScreenTarget(
  9.     WindowPtr window)
  10. {
  11.     UpdateFromWindow(window);
  12. }
  13.  
  14.  
  15. ScreenTarget::~ScreenTarget()
  16. {
  17. }
  18.  
  19.  
  20. void
  21. ScreenTarget::UpdateFromWindow(
  22.     WindowPtr window)
  23. {
  24.     Rect globalRect = window->portRect;
  25.     GrafPtr savePort;
  26.     GetPort(&savePort);
  27.     SetPort(window);
  28.     LocalToGlobal(&topLeft(globalRect));
  29.     LocalToGlobal(&botRight(globalRect));
  30.     GDHandle theDevice = GetMaxDevice(&globalRect);
  31.     PixMapHandle thePixMap = (*theDevice)->gdPMap;
  32.  
  33.     char *tba = GetPixBaseAddr(thePixMap);
  34.     rowBytes = (*thePixMap)->rowBytes&0x3fff;
  35.     int indenth = 8 - (globalRect.left&7); // ensure double alignment
  36.     tba += indenth+globalRect.left;
  37.     tba += globalRect.top*rowBytes;
  38.     width = ((globalRect.right-globalRect.left-indenth)&~7)/2;
  39.     height = (globalRect.bottom-globalRect.top)/2;
  40.     addRowBytes = rowBytes-(width*2);
  41.     baseAddr = tba;
  42.     SetPort(savePort);
  43. }
  44.  
  45.  
  46. void
  47. ScreenTarget::PutData(
  48.     const void *inPtr,
  49.     long inRowBytes,
  50.     long inWidth,
  51.     long inNumRows,
  52.     long destRow,
  53.     long destCol)
  54. {
  55.     const int cAddRowBytes = (inRowBytes-inWidth)>>2; // in longs
  56.     const long *srcPtr = (long *)inPtr;
  57.     const int cWidth = inWidth>>2; // num longs
  58.  
  59.     const int dAddRowBytes = (rowBytes+addRowBytes)>>3; // in doubles, two scan lines
  60.     double *dstPtr = (double *)baseAddr;
  61.     double *dstPtr2 = ((double*)dstPtr)+(rowBytes>>3);
  62.     double dBuf;
  63.     double *dBufP = 1+&dBuf;
  64.  
  65.     int h = inNumRows;
  66.  
  67.     srcPtr--; // adjust for pre-increment
  68.     dstPtr--;
  69.     dstPtr2--;
  70.  
  71.     while (--h >= 0) {
  72.         int v = cWidth;
  73.         while (--v >= 0) {
  74.             long l = *++srcPtr;
  75.             char *d = (char *)dBufP;
  76.             long l2 = l >> 8;
  77.             *--d = l;
  78.             *--d = l;
  79.             long l3 = l >> 16;
  80.             *--d = l2;
  81.             *--d = l2;
  82.             long l4 = l >> 24;
  83.             *--d = l3;
  84.             *--d = l3;
  85.             *--d = l4;
  86.             *--d = l4;
  87.             double dd = dBuf;
  88.             *++dstPtr = dd;
  89.             *++dstPtr2 = dd;
  90.         }
  91.         dstPtr += dAddRowBytes;
  92.         srcPtr += cAddRowBytes;
  93.     }
  94. }
  95.  
  96.